/**
*@Author      ：anlzou
*@Date        ：15:58 2021/4/23
*@Github      ：https://github.com/anlzou
*@Description ：
*/
package com.anlzou.cr_runnable_bank;

import com.anlzou.bank.Bank;

public class ThreadsBank {

    Bank bank = new Bank();

    public ThreadsBank(Bank bank){
        this.bank = bank;
    }

    public Thread tadd(final int number){
        return new Thread(new Runnable() {
            public void run() {
                while (true) {
                    bank.addMoney(number);
                    bank.lookMoney();
                    System.out.println("\n");

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

    public Thread tsub(final int number){
        return new Thread(new Runnable() {
            public void run() {
                while (true) {
                    bank.subMoney(number);
                    bank.lookMoney();
                    System.out.println("\n");

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
